new Vue({
    el: "#app",
    data() {
        return {
            form: {
                Store_SerialNumber: "",
                page: 1,			//页数
                limit: 10,			//每页数据条数

            },
            total: 1,
            tableData: [
                {
                    Delivery_SerialNumber: "",
                    Store_SerialNumber: "测试",
                    longitude: '126.960273',
                    latitude: '47.463812',
                    Enterprise_Info_SerialNumber: $.cookie('enterprise'),
                    Children: {
                        delivery_detail: [{
                            Delivery_Detail_SerialNumber: '',
                            Delivery_SerialNumber: '',
                            Delivery_Distance: '10',
                            Delivery_Amount: '200',
                            Sales_Amount: '300'
                        }]
                    }
                }
            ],
            query_content: "",
            select_list: [],

        };
    },
    mounted() {
        this.get_select_list();
    },
    methods: {
        query() {
            this.form.page = 1;
            this.getList(this.form)
            // this.tableData.filter(
            //     (item) => item.Store_SerialNumber = this.Store_SerialNumber
            // )
        },
        //请求下拉框数据
        get_select_list() {
            const _this = this;
            $.ajax({
                url: DomainName + '/getInquiryAction?token=' + $.cookie("token"),
                data: {
                    Data: 'store_info',
                },
                type: "POST",
                complete: function (XMLHttpRequest) {
                    _this.loading = false
                    if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                        window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                    }
                },
                success: function (res) {
                    console.log(res);
                    _this.select_list = res;
                    //    select_list
                }
                ,
                dataType: "json"
            });
        },

        new_xt(Delivery_SerialNumber) {
            sessionStorage.setItem("Delivery_SerialNumber", Delivery_SerialNumber)
            window.location.href = './Edit.html'
        },
        //下拉查询
        getChildrentab(row) {
            const _this = this;
            $.ajax({
                url: DomainName + "/getInquiryIDAction?token=" + $.cookie("token"),
                data: {
                    Primary_Key_Name: 'Delivery_SerialNumber',
                    Primary_Key: row.Delivery_SerialNumber,
                    Data: "delivery_detail",
                    isNullEnterprise: true
                }
                ,
                type: "POST",
                complete: function (XMLHttpRequest) {
                    _this.loading = false
                    if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                        window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                    }
                },
                success: function (res) {
                    row.Children.delivery_detail = res
                }
                ,
                dataType: "json"
            });
        },
        //查询所有的仓库数据
        getList(data) {
            const _this = this;
            $.ajax({
                url: DomainName + "/getDeliveryInfoAction?token=" + $.cookie("token"),
                data,
                type: "post",
                complete: function (XMLHttpRequest) {
                    _this.loading = false
                    if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                        window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                    }
                },
                success: function (res) {
                    console.log(res);
                    _this.tableData = res.tableData    //将获取的数据存到表格数据中
                },
                dataType: "json"
            });
        },

        Cancle() {
            this.dialogFormVisible = false
            this.formData.num = ''
            this.formData.address = ''
        },
        //号码改变查询
        handleSizeChange(val) {
            this.form.page = 1;
            this.form.limit = val;
            this.getList(this.form)
        },
        //号码按键查询
        handleCurrentChange(val) {
            this.form.page = val;
            this.getList(this.form)
        },
        omitMember(Delivery_SerialNumber) {
            const _this = this;
            this.$confirm('是否确认删除, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() => {
                $.ajax({
                    url: DomainName + '/getInquiryIDOriginal?token=' + $.cookie('token'),
                    type: 'POST',
                    data: {
                        Primary_Key_Name: 'Delivery_SerialNumber',
                        Primary_Key: Delivery_SerialNumber,
                        Data: "delivery_info"
                    },
                    success: function (res) {
                        if (res.length == 1) {
                            res[0].Row_Status = '1'
                            detel = res[0];
                            let data = { Data: JSON.stringify({ Modify: { delivery_info: [detel] } }) };
                            $.ajax({
                                url: DomainName + '/getEditAction?token=' + $.cookie('token'),
                                type: 'POST',
                                data,
                                success: function (res) {
                                    if (res.Status === 'success') {
                                        _this.$message.success("删除成功");
                                        _this.getList(_this.form);
                                    } else {
                                        _this.$message.error("操作失败，请稍后再试")
                                    }
                                },
                                error: function () {
                                    _this.$message.error("操作失败，请稍后再试")
                                },
                                complete: function (XMLHttpRequest) {
                                    _this.loading = false
                                    if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                                        window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                                    }
                                }
                            })
                        }
                    }
                })
            }).catch(() => {
                this.$message({
                    type: 'warning',
                    message: '已取消删除'
                });
            });
        },
        addEnterprise() {//去增加仓库页
            window.location.href = './Add.html'
        },
        back() {//返回上一页
            window.history.go(-1)
        }
    },
    created() {
        this.getList(this.form)
    }
});
